@ECHO OFF

REM
REM Define the environment.
REM
CALL SET_ENV.BAT

REM
REM Select the sf environment.
REM
CLS
ECHO +-----------------------------------------------------------------------------+
ECHO ^|                                                                             ^|
ECHO ^|                 PLEASE SELECT YOUR SFDC ENV                                 ^|
ECHO ^|                                                                             ^|
ECHO +-----------------------------------------------------------------------------+
ECHO Please select your Salesforce.com environment :
ECHO 1. ORG 1
ECHO 2. ORG 2
ECHO 3. exit
CHOICE /C:123
SET ENV=%ERRORLEVEL%

IF %ENV% EQU 1 GOTO ORG1
IF %ENV% EQU 2 GOTO ORG2
IF %ENV% EQU 3 GOTO END

:ORG1
SET ENV=ORG1
GOTO CONFIGURE

:ORG2
SET ENV=ORG2
GOTO CONFIGURE

:CONFIGURE
IF %1 == r GOTO CONFIG_RETRIEVE
IF %1 == s GOTO CONFIG_SIMU
IF %1 == d GOTO CONFIG_DEPLOY

:CONFIG_RETRIEVE
SET INFO_LABEL=Retrieve
SET SRC_LABEL=Metadatas listed in
SET ENV_LABEL=From instance
SET SRC_FILE=%2\Retrieve.xml
SET DEST_PATH=%2\Retrieve_%DATE:~0,2%-%DATE:~3,2%-%DATE:~6,4%_%TIME:~0,2%h%TIME:~3,2%m%TIME:~6,2%s
MKDIR "%DEST_PATH%"
SET CMD_PARAMS=SfRetrieve -buildfile sf_actions.xml -Dsf_env=%ENV% -Dsf_action=%1 -Dretrieve_path=%DEST_PATH% -Dmetas_file_path=%SRC_FILE%
GOTO CONFIRM

:CONFIG_SIMU
SET INFO_LABEL=Simulation
GOTO CONFIG_SIMU_DEPLOY

:CONFIG_DEPLOY
SET INFO_LABEL=Deployment

:CONFIG_SIMU_DEPLOY
SET SRC_LABEL=From file
SET ENV_LABEL=To instance
SET SRC_FILE=%2\Package.zip
SET CMD_PARAMS=SfSimuDeploy -buildfile sf_actions.xml -Dsf_env=%ENV% -Dsf_action=%1 -Dzip_file_path=%SRC_FILE%
GOTO CONFIRM


:CONFIRM
CLS
ECHO +-----------------------------------------------------------------------------+
ECHO ^|                                                                             ^|
ECHO ^|                 PLEASE CONFIRM                                              ^|
ECHO ^|                                                                             ^|
ECHO +-----------------------------------------------------------------------------+
ECHO Your about to :
ECHO - Do a %INFO_LABEL%
ECHO - %SRC_LABEL% : %SRC_FILE%
ECHO - %ENV_LABEL% : %ENV%
REM ECHO - Params : %CMD_PARAMS% 
ECHO.
ECHO ARE YOU SURE ?
ECHO 1. Yes
ECHO 2. No
CHOICE /C:12
IF %ERRORLEVEL% EQU 2 GOTO END

:EXEC
CLS
ECHO +-----------------------------------------------------------------------------+
ECHO ^|                                                                             ^|
ECHO ^|                 %INFO_LABEL% IS STARTING                                      ^|
ECHO ^|                                                                             ^|
ECHO +-----------------------------------------------------------------------------+
CALL %ANT_EXEC% %CMD_PARAMS%

:END